package com.ctshk.sapp.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.AppVersionDTO;
import com.ctshk.rpc.cms.req.AppVersionAddReq;
import com.ctshk.rpc.cms.req.AppVersionQueryReq;
import com.ctshk.rpc.cms.req.AppVersionUpdateReq;
import com.ctshk.rpc.cms.req.AppVersionUpdateStatusReq;
import com.ctshk.rpc.cms.service.IAppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * app版本 管理 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "app版本管理", tags = "app版本管理")
@RestController
@RequestMapping("/app-version")
public class AppVersionController extends BaseController {

    @DubboReference
    private IAppVersionService appVersionService;

    @ApiOperation(value = "新增app版本", notes = "新增app版本")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody @Valid AppVersionAddReq req) {
        return appVersionService.insert(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询app版本", notes = "查询app版本")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/queryById/{id}")
    public Result<AppVersionDTO> queryById(@PathVariable("id") Long id) {
        return appVersionService.queryById(id);
    }

    @ApiOperation(value = "app版本分页查询", notes = "app版本分页查询")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryList")
    public Result<PageResponse<AppVersionDTO>> queryList(@RequestBody @Valid AppVersionQueryReq req) {
        return Result.success(appVersionService.queryList(req));
    }

    @ApiOperation(value = "修改app版本", notes = "修改app版本")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid AppVersionUpdateReq req) {
        return appVersionService.update(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改app版本状态", notes = "修改app版本状态")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/updateStatus")
    public Result update(@RequestBody @Valid AppVersionUpdateStatusReq req) {
        return appVersionService.updateByStatus(req);
    }
}
